typescript 需要额外定义类型
1 | import React from "react"; |
对于查询参数也需要定义类型
1 | type InputProps = { |
在包装组件获取 props 时也需要定义
1 | import React from "react"; |
使用class组件定义
import { ChildProps } from "react-apollo"; const withCharacter = graphql<Response, InputProps>(HERO_QUERY, { options: ({ episode }) => ({ variables: { episode } }) }); class Character extends React.Component<ChildProps<InputProps, Response>, {}> { render(){ const { loading, hero, error } = this.props.data; if (loading) return <div>Loading</div>; if (error) return <h1>ERROR</h1>; return ...// actual component with data; } } export default withCharacter(Character);